package com.dingreading.cloud.admin.util;

import com.dingreading.cloud.admin.entity.HeadStaff;
import com.dingreading.cloud.admin.entity.Staff;
import com.dingreading.cloud.admin.entity.Stores;
import com.dingreading.cloud.admin.service.HeadStaffService;
import com.dingreading.cloud.admin.service.StaffService;
import com.dingreading.cloud.admin.service.StoresService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Component
public class UidUtil {

    public static UidUtil util;

    @PostConstruct
    public void init() {
        util = this;
    }

    @Resource
    private StoresService storesService;
    @Resource
    private StaffService staffService;
    @Resource
    private HeadStaffService headStaffService;

    /**
     * 根据门店uid获取
     *
     * @param storeUid 门店uid
     */
    public static Object getStore(String storeUid) {
        if (StringUtils.isBlank(storeUid)) return "门店uid不能为空";

        Stores storesObj = util.storesService.getByUid(storeUid);
        if (storesObj == null) return "门店不存在";

        if (!storesObj.getEnabled().equals(1)) return "门店已被禁用";

        return storesObj;
    }

    /**
     * 根据门店uid获取
     *
     * @param storeId 门店uid
     */
    public static Object getStore(Long storeId) {
        if (storeId == null || storeId <= 0) return "门店id不能为空";

        Stores storesObj = util.storesService.getById(storeId);
        if (storesObj == null) return "门店不存在";

        if (!storesObj.getEnabled().equals(1)) return "门店已被禁用";

        if (storesObj.getCooperationType() == null) return "未设置加盟商的合作类型";

        return storesObj;
    }

    /**
     * 根据门店员工uid获取
     *
     * @param staffUid 门店员工uid
     */
    public static Object getStaff(String staffUid) {
        if (StringUtils.isBlank(staffUid)) return "门店员工uid不能为空";

        Staff staffObj = util.staffService.getByUid(staffUid);
        if (staffObj == null) return "门店员工不存在";

        if (!staffObj.getEnabled().equals(1)) return "门店员工已被禁用";

        return staffObj;
    }

    /**
     * 根据总部员工id获取
     *
     * @param id 总部员工id
     */
    public static Object getHeadStaff(Long id) {
        if (id == null) return "总部员工id不能为空";

        HeadStaff headStaffObj = util.headStaffService.getById(id);
        if (headStaffObj == null) return "总部员工不存在";

        if (!headStaffObj.getEnabled().equals(1)) return "总部员工已被禁用";

        return headStaffObj;
    }

    public static Object getHeadStaff(String uid) {
        if (StringUtils.isBlank(uid)) return "总部员工id不能为空";

        HeadStaff headStaffObj = util.headStaffService.getByUid(uid);
        if (headStaffObj == null) return "总部员工不存在";

        if (!headStaffObj.getEnabled().equals(1)) return "总部员工已被禁用";

        return headStaffObj;
    }

}